/*******************************************************************************
 * Copyright (c) 2014 Francesco Gabbrielli.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Francesco Gabbrielli - initial API and implementation
 ******************************************************************************/
package it.francescogabbrielli.android.solidalapp.file;

import android.os.Bundle;
import android.support.v4.content.Loader;
import it.francescogabbrielli.android.solidalapp.Constants;
import it.francescogabbrielli.android.solidalapp.DataEvent;
import it.francescogabbrielli.android.solidalapp.EndpointsLoader;
import it.francescogabbrielli.android.solidalapp.IntentAction;
import it.francescogabbrielli.android.solidalapp.R;
import it.francescogabbrielli.android.solidalapp.SolidalApp.DataKey;
import it.francescogabbrielli.android.solidalapp.StatusEvent;
import it.francescogabbrielli.android.solidalapp.requestendpoint.model.Request;
import it.francescogabbrielli.android.solidalapp.responseendpoint.model.Response;


public class ResponseFileActivity extends FileActivity<Request> {
	
	private final static long RESPONSE_BASE_ID = 10000000L;

	@Override
	public void onStatusUpdate(StatusEvent event) {
		
	}
	
	@Override
	public void onDataChanged(DataEvent event) {
		
	}
	
	@Override
	protected String getProfileFragmentName() {
		return ResponseFileFragment.class.getName();
	}
	
	@Override
	public long getBaseId() {
		return RESPONSE_BASE_ID;
	}
	
	@Override
	public DataKey getChatKey() {
		return DataKey.CHAT_RESPONSE;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Response res = (Response) app.getData(DataKey.RESPONSE);
		if (res!=null) {
			setTitle(getString(R.string.title_activity_file, res.getId()));
			reload(false, res.getRequestId(), Constants.LOADER_FILE_REQUEST);
		}
	}
			
	@Override
	public void sendMessage(long id, String message) {
		Bundle data = new Bundle();
		data.putLong("id", id);
		data.putString("message", message);
		IntentAction.GCM_SEND_RESPONSE_CHAT.start(this, data, 0);	
	}
	
	@Override
	public Loader<Request> onCreateLoader(int id, Bundle data) {
		return new EndpointsLoader<Request>(this, Request.class)
				.setFilters(data)
				.setMethod("getRequest");
	}

	@Override
	public void onLoadFinished(Loader<Request> loader, Request request) {
		app.setData(DataKey.FILE_REQUEST, request);
	}

	@Override
	public void onLoaderReset(Loader<Request> loader) {
	}

}
